package com.study.springmvc.config;

import org.springframework.lang.NonNull;

import java.util.concurrent.ThreadFactory;
import java.util.concurrent.atomic.AtomicInteger;

public class CustomThreadFactory implements ThreadFactory {

    private final String prefix;

    public CustomThreadFactory(String prefix) {
        this.prefix = prefix;
    }

    private final AtomicInteger threadNumber = new AtomicInteger(1);

    public Thread newThread(@NonNull Runnable task) {
        return new Thread(task, prefix + threadNumber.getAndIncrement());
    }
}
